package service

import (
	"github.com/gin-gonic/gin"
	"zk2/product-guard/internal/dto"
	"zk2/product-guard/internal/model"
	"zk2/product-guard/response"
)

func CreateWindowClassify(c *gin.Context) {

	var WindowClassify model.WindowClassify
	err := c.ShouldBind(&WindowClassify)
	if err != nil {
		response.Error(c, "参数错误")
		return
	}
	var NewWindowClassify model.WindowClassify
	err = c.ShouldBind(&WindowClassify)
	if err != nil {
		response.Error(c, "参数错误")
		return
	}
	NewWindowClassify = model.WindowClassify{
		ShopId: NewWindowClassify.ShopId,
		Name:   NewWindowClassify.Name,
	}
	if NewWindowClassify.Name == WindowClassify.Name {
		response.Error(c, "分类名称重复")
		return
	}
	err = dto.CreateWindowClassify(&NewWindowClassify)
	if err != nil {
		response.Error(c, "添加失败")
		return
	}
	response.Success(c, "添加成功", NewWindowClassify.ID)

}
